package edu.gyc.hiseckill.code;

import edu.gyc.hiseckill.dao.RandomCodeDao;
import edu.gyc.hiseckill.model.RandomCode;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

@Slf4j
public class CodeGenerateThread implements Runnable{

    private RandomCodeDao randomCodeMapper;

    public CodeGenerateThread(RandomCodeDao randomCodeMapper) {
        this.randomCodeMapper = randomCodeMapper;
    }

    @Override
    public void run() {
        //生成订单编号并插入数据库
        RandomCode entity=new RandomCode();
        //高并发下还是会有重复
      //  entity.setCode(RandomUtil.generateOrderCode());
        //UUID不重复，生成的id无意义，不好用
       // entity.setCode(UUID.randomUUID().toString());
        entity.setCode(SeqUtil.generateOrderCode());
        log.info(Thread.currentThread().getName()+" "+entity);
        randomCodeMapper.insert(entity);
    }
}
